package com.shizhanzhe.qdd.home.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shizhanzhe.qdd.R;
import com.shizhanzhe.qdd.home.bean.YxBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 * @author YJ
 * @date 2018/10/23
 */
public class ApprenticeAdapter extends RecyclerView.Adapter<ApprenticeAdapter.ViewHolder> {
    private Context mContext;
    private List<YxBean.DataBeanX.DataBean> mData = new ArrayList<>();

    public ApprenticeAdapter(Context context) {
        mContext = context;
    }

    public void updateData(int page, List<YxBean.DataBeanX.DataBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            if (page == 1) {
                mData = dataSet;
            } else {
                mData.addAll(dataSet);
            }
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_apprentice_details, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        YxBean.DataBeanX.DataBean dataBean = mData.get(position);
        holder.xuhao.setText(dataBean.getUid()+"");
        holder.nicknam.setText(dataBean.getUname());
        if (dataBean.getIncome() != 0){
            holder.status.setText("有效");
            holder.money.setText("+" + dataBean.getIncome());
            holder.money.setTextColor(mContext.getResources().getColor(R.color.them));
            holder.view.setVisibility(View.GONE);
        } else {
            holder.status.setText("未激活");
            holder.money.setText("0");
            holder.money.setTextColor(mContext.getResources().getColor(R.color.gray));
            holder.view.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.xuhao)
        TextView xuhao;
        @BindView(R.id.nicknam)
        TextView nicknam;
        @BindView(R.id.status)
        TextView status;
        @BindView(R.id.money)
        TextView money;
        @BindView(R.id.view)
        View view;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
